package com.zzpct.wh.myvrwork;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzpct.wh.myvrwork.entity.Cars;
import com.zzpct.wh.myvrwork.entity.Guzhang;
import com.zzpct.wh.myvrwork.entity.service.CarsService;
import com.zzpct.wh.myvrwork.entity.Youjia;
import com.zzpct.wh.myvrwork.entity.service.GuzhangService;
import com.zzpct.wh.myvrwork.entity.service.YoujiaService;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //getCareinfo();
        //getYoujiainfo();
        getGuzhangInfo();
    }

    private void getGuzhangInfo() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/obdcode/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        GuzhangService guzhangService=retrofit.create(GuzhangService.class);
        Map<String,String> map=new HashMap<>();
        map.put("key","6b40135084049a9641f5dc01af7ed188&code=P2079");
        map.put("code","P2078");
        Call<Guzhang> call = guzhangService.getGuzhangxinxi(map);
        call.enqueue(new Callback<Guzhang>() {
            @Override
            public void onResponse(Call<Guzhang> call, Response<Guzhang> response) {
                Guzhang guzhang=response.body();
                Log.d(TAG, "onResponse: "+guzhang.getResult().getGzfw());
            }

            @Override
            public void onFailure(Call<Guzhang> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());

            }
        });
    }

    private void getYoujiainfo() {
        Retrofit y=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/gnyj/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        YoujiaService youjiaService=y.create(YoujiaService.class);
        Call<Youjia> call = youjiaService.getAll("e0106d4f036cf6d539ae0469d19545b2");
        call.enqueue(new Callback<Youjia>() {
            @Override
            public void onResponse(Call<Youjia> call, Response<Youjia> response) {

            }

            @Override
            public void onFailure(Call<Youjia> call, Throwable t) {

            }
        });
    }

    private void getCareinfo() {
        Retrofit r=new Retrofit.Builder()
                .baseUrl("http:/www.hnzzsgz.cn:5001/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        CarsService carsService=r.create(CarsService.class);
        Call<Cars> all = carsService.getAll();
        all.enqueue(new Callback<Cars>() {
            @Override
            public void onResponse(Call<Cars> call, Response<Cars> response) {
                Cars carlist = response.body();
                Log.d(TAG, "onResponse: "+carlist.getData().get(1).getCarno());
            }

            @Override
            public void onFailure(Call<Cars> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());

            }
        });
    }
}
